package org.linlinjava.litemall.db.service;

import com.github.yulichang.base.MPJBaseServiceImpl;
import org.linlinjava.litemall.db.dao.LumiereCalculateSettlementMapper;
import org.linlinjava.litemall.db.domain.LumiereCalculateSettlement;
import org.linlinjava.litemall.db.domain.LumiereCalculateSettlementExample;
import org.springframework.cglib.core.Local;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;

@Service
public class LumiereCalculateSettlementService extends MPJBaseServiceImpl<LumiereCalculateSettlementMapper,LumiereCalculateSettlement> {

    @Resource
    private LumiereCalculateSettlementMapper lumiereCalculateSettlementMapper;

    public void add(LumiereCalculateSettlement settlement){
        lumiereCalculateSettlementMapper.insert(settlement);
    }

    public List<LumiereCalculateSettlement> queryLast(Integer shopId){
        LumiereCalculateSettlementExample example = new LumiereCalculateSettlementExample();
        LumiereCalculateSettlementExample.Criteria criteria = example.createCriteria();
        criteria.andShopIdEqualTo(shopId);

        criteria.andAddTimeBetween(LocalDateTime.of(LocalDate.now(), LocalTime.MIN), LocalDateTime.of(LocalDate.now(), LocalTime.MAX));

        example.setOrderByClause("add_time" + " " + "desc");

        return lumiereCalculateSettlementMapper.selectByExample(example);
    }

}
